package com.lx.mobileplayer.mvp.view.fragment

import android.Manifest
import android.content.DialogInterface
import android.view.View
import com.lx.mobileplayer.R
import com.lx.mobileplayer.utils.LogUtil
import com.lx.mobileplayer.utils.ToastUtil
import com.lx.permission.PermissionCallback
import com.lx.permission.PermissionUtil
import kotlinx.android.synthetic.main.fragment_vbang.*

/**
 * 类说明：首页
 * Created by liuxiong on 2019/4/24.
 */
class VBangFragment :BaseFragment(){

    override fun initContentView(): View {
        return View.inflate(getMContext(), R.layout.fragment_vbang,null)
    }

    override fun initView() {
        super.initView()

        text_view.setOnClickListener {
            var permission= arrayOf(
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.CAMERA,
                Manifest.permission.READ_PHONE_STATE
            )

            PermissionUtil.request(activity,permission,object : PermissionCallback {
                override fun onPermissionGranted() {
//                PermissionUtil.showDialog(activity,"权限申请成功")
                    ToastUtil.show("权限申请成功")
                }

                override fun shouldShowRational(rationalPermissons: Array<out String>?,before:Boolean ) {
//                    PermissionUtil.showDialog(activity,"权限申请失败")

                    rationalPermissons?.let {
                        for(str in rationalPermissons){
                            LogUtil.d("shouldShowRational---$str")
                        }

                        PermissionUtil.showDialog(activity,"我们获取xxx权限仅用于xxx") { dialog, which ->

                            dialog.dismiss()

                            //重新申请权限
                            PermissionUtil.requestAgain(activity,permission,this)
                        }
                    }
                }

                override fun onPermissonReject(rejectPermissons: Array<out String>?) {
                    rejectPermissons?.let {
                        for(str in rejectPermissons){
                            LogUtil.d("onPermissonReject---$str")
                        }

                        PermissionUtil.showDialog(activity,"xxx功能需要的xxx权限被禁止，请到设置里设置权限") { dialog, which ->

                            dialog.dismiss()

                            //重新申请权限
                            PermissionUtil.startSettingsActivity(activity)
                        }
                    }
                }
            })
        }
    }

}